package com.cskaoyan.market.service;

import com.cskaoyan.market.db.domain.MarketFeedback;
import com.cskaoyan.market.db.domain.MarketUser;
import com.cskaoyan.market.db.mapper.MarketFeedbackMapper;
import com.cskaoyan.market.db.mapper.MarketUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
public class WxFeedBackServiceImpl implements WxFeedBackService {

    @Autowired
    MarketUserMapper userMapper;
    @Autowired
    MarketFeedbackMapper feedbackMapper;

    @Override
    public int submit(String content, String feedType, boolean hasPicture, String mobile, String[] picUrls,
                      int userId) {

        MarketUser user = userMapper.selectByPrimaryKey(userId);
        String username = user.getUsername();
        int status = 0;

        MarketFeedback marketFeedback = new MarketFeedback();
        marketFeedback.setContent(content);
        marketFeedback.setFeedType(feedType);
        marketFeedback.setHasPicture(hasPicture);
        marketFeedback.setMobile(mobile);
        marketFeedback.setPicUrls(picUrls);
        marketFeedback.setAddTime(LocalDateTime.now());

        marketFeedback.setStatus(status);

        marketFeedback.setUserId(userId);
        marketFeedback.setUsername(username);

        marketFeedback.setAddTime(LocalDateTime.now());
        marketFeedback.setUpdateTime(LocalDateTime.now());
        marketFeedback.setDeleted(false);

        feedbackMapper.insert(marketFeedback);

        return 200;
    }

}
